﻿namespace MefContrib.Models.Provider.Definitions.Attributed
{
    using System;
    using MefContrib.Models.Provider.Validation;

    /// <summary>
    /// 
    /// </summary>
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
    public class ExportableAttribute : Attribute
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ExportableAttribute"/> class, using
        /// the provided contract type.
        /// </summary>
        public ExportableAttribute()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ExportableAttribute"/> class, using
        /// the provided contract type.
        /// </summary>
        /// <param name="contractType"></param>
        public ExportableAttribute(Type contractType)
        {
            contractType
                .Require("contractName")
                .NotNull();

            ContractType = contractType;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ExportableAttribute"/> class, using
        /// the provided contract name.
        /// </summary>
        /// <param name="contractName"></param>
        public ExportableAttribute(string contractName)
        {
            contractName
                .Require("contractName")
                .NotNull()
                .NotEmpty();

            ContractName = contractName;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ExportableAttribute"/> class, using
        /// the provided contract name.
        /// </summary>
        /// <param name="contractName"></param>
        /// <param name="contractType"></param>
        public ExportableAttribute(string contractName, Type contractType)
        {
            contractName
                .Require("contractName")
                .NotNull()
                .NotEmpty();

            contractType
                .Require("contractName")
                .NotNull();

            ContractName = contractName;

            ContractType = contractType;
        }

        /// <summary>
        /// Gets the name of the contract.
        /// </summary>
        /// <value>A <see cref="string"/> containing the name of the contract.</value>
        public string ContractName { get; protected set; }

        /// <summary>
        /// Gets the contract type that is exported by the member that this attribute is attached to.
        /// </summary>
        public Type ContractType { get; protected set; }
    }
}
